import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_app/components/layout.dart';
import 'package:flutter_app/generated/l10n.dart';
class MyPage extends StatefulWidget {
  @override
  _MyPageState createState() => _MyPageState();
}

class ListItem {
  String text;
  String url;
  String icon;
  Widget right;

  ListItem({this.text, this.url, this.icon, this.right});
}



class _MyPageState extends State<MyPage> {
  bool isLogin=true;
  @override
  Widget build(BuildContext context) {
    void gotoPage(path) {
      Navigator.pushNamed(context, path);
    }
    List<ListItem> LIST_ITEMS = [
      //投资记录
      ListItem(
          text: S.of(context).invest_record,
          url: "/invest/record",
          icon: 'assets/images/ic_me_investment_record.png'),
      //身份认证
      ListItem(
          text: S.of(context).identity,
          url: '/auth/home',
          icon: 'assets/images/ic_me_kyc.png',
          right: Text('Lv.2 ',style: TextStyle(color: Colors.blueAccent,fontSize: 17),)),
      //帮助与社群
      ListItem(
          text: S.of(context).help, url: '/help', icon: 'assets/images/ic_help_center.png'),
      //邀请好友
      ListItem(
          text: S.of(context).invite,
          url: '/invite',
          icon: 'assets/images/ic_invite_friends.png',
          right: Image.asset(
            'assets/images/ic_usdt_shake.gif',
            width: 40,
          )),
     // 优惠券
      ListItem(
        text: S.of(context).coupons,
        url: '/coupon',
        icon: 'assets/images/ic_me_coupons.png',
      ),
      //矩阵新人礼
      ListItem(
          text: S.of(context).new_gift,
          url: '/gift',
          icon: 'assets/images/ic_newbie_gift.png',
          right: Text(
            '领 1288 USDC ',
            style: TextStyle(color: Colors.blueAccent),
          )),
    ];
    List<Widget> getItems() {
      return LIST_ITEMS.map((item) {
        return InkWell(
          onTap: () => gotoPage(item.url),
          child: Container(
            padding: const EdgeInsets.symmetric(vertical: 10.0),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Row(
                  children: [
                    Image.asset(item.icon, width: 33),
                    SizedBox(
                      width: 10,
                    ),
                    Text(
                      item.text,
                      style: TextStyle(fontSize: 15),
                    ),
                  ],
                ),
                Row(
                  children: [
                    Offstage(
                      offstage: item.right == null,
                      child: item.right,
                    ),
                    Container(
                      child: Image.asset('assets/images/ic_arrow_right.png',
                          width: 12),
                    ),
                  ],
                )
              ],
            ),
          ),
        );
      }).toList();
    }

    return AnnotatedRegion<SystemUiOverlayStyle>(
      value: SystemUiOverlayStyle.dark,
      child: SafeArea(
        child: RefreshIndicator(
          onRefresh: () async {},
          child: SingleChildScrollView(
            child: Column(children: [
              //标题
              Padding(
                padding: const EdgeInsets.symmetric(horizontal: 15),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Text(S.of(context).tab_me, style: TextStyle(fontSize: 22)),
                    IconButton(
                        icon: Icon(Icons.settings, color: Colors.black),
                        onPressed: () => gotoPage('/set'))
                  ],
                ),
              ),
              //头像
              Padding(
                padding: const EdgeInsets.fromLTRB(15, 20, 15, 18),
                child: RowBetween(children: [
                  Row(
                    children: [
                      Container(
                        width: 50,
                        height: 50,
                        alignment: Alignment.center,
                        margin: EdgeInsets.fromLTRB(0, 0, 20, 0),
                        decoration: BoxDecoration(
                            image: DecorationImage(
                                image: AssetImage("assets/images/Avatar.png"),
                                fit: BoxFit.cover),
                            borderRadius: BorderRadius.circular(1000)),
                      ),
                      Offstage(
                        offstage: isLogin,
                        child: SizedBox(
                            height: 30,
                            width: 70,
                            child: FlatButton(
                                onPressed: () {
                                  Navigator.pushNamed(context, '/login');
                                },
                                color: Colors.blueAccent,
                                textColor: Colors.white,
                                child: Text('登录'))
                        ),
                      ),
                      Offstage(
                        offstage: !isLogin,
                        child: GestureDetector(
                          onTap: (){Navigator.pushNamed(context, '/safe');},
                          child: Text(
                                '180****6091',
                                style: TextStyle(
                                    fontWeight: FontWeight.bold, fontSize: 20),
                              ),
                        ),
                      )
                    ],
                  ),
                  IconButton(
                    icon: Icon(Icons.arrow_forward_ios),
                    onPressed: (){Navigator.pushNamed(context, '/safe');},
                    iconSize: 16,
                  )
                ]),
              ),
              //会员中心
              GestureDetector(
                onTap: ()=>Navigator.pushNamed(context, '/vip'),
                child: Stack(
                  children: [
                    Container(
                      margin: EdgeInsets.fromLTRB(15, 0, 15, 0),
                      decoration: BoxDecoration(
                        color: Color(0xFF2C6DFD),
                        borderRadius: BorderRadius.circular(6),
                      ),
                      padding: EdgeInsets.symmetric(vertical: 18.0, horizontal: 14.0),
                      child: ColumnStart(
                        children: [
                          Row(
                            children: [
                              Text(
                                'Batsoft 会员',
                                style: TextStyle(color: Colors.white),
                              ),
                              SizedBox(width: 5),
                              Image.asset(
                                'assets/images/level/ic_vip_level1.png',
                                width: 17,
                              ),
                            ],
                          ),
                          Text(
                            '财富分：0',
                            style: TextStyle(color: Colors.white),
                          )
                        ],
                      ),
                    ),
                    Positioned(
                      top: 22,
                      right:12,
                      child: Container(
                        width: 100,
                        padding:EdgeInsets.symmetric(vertical: 5.0,horizontal: 5.0),
                        decoration: BoxDecoration(
                          color: Color(0xFF115AF4),
                          borderRadius: BorderRadius.only(topLeft: Radius.circular(16),bottomLeft:Radius.circular(16))
                        ),
                        child: RowBetween(
                          children: [
                            SizedBox(
                              width:10.0
                            ),
                            Text(
                              '会员中心',
                              style: TextStyle(color: Colors.white,fontSize: 13),
                            ),
                            SizedBox(
                              width:8
                            ),
                            Icon(
                              Icons.arrow_forward_ios_outlined,
                              color: Colors.white,
                              size: 15,
                            )
                          ],
                        ),
                      ),
                    )
                  ],
                ),
              ),
              //列表项
              Container(
                color: Colors.white,
                child: Padding(
                    padding:
                        const EdgeInsets.symmetric(horizontal: 15, vertical: 18),
                    child: Wrap(
                      children: getItems(),
                    )),
              )
            ]),
          ),
        ),
      ),
    );
  }
}
